<template>
  <div class="container-content">
    <el-form
      ref="elForm"
      :model="formData"
      :rules="rules"
      size="medium"
      label-width="100px"
    >
      <!-- <el-form-item label-width="200px" label="编码" prop="bizCode">
        <el-input
          v-model="formData.bizCode"
          placeholder="请输入编码"
          clearable
          :style="{ width: '100%' }"
        >
        </el-input>
      </el-form-item> -->
      <el-form-item label-width="200px" label="数据状态" prop="dataStatus">
        <el-select
          v-model="formData.dataStatus"
          placeholder="请选择数据状态"
          clearable
          :style="{ width: '100%' }"
        >
          <el-option
            v-for="(item, index) in dataStatusOptions"
            :key="index"
            :label="item.label"
            :value="item.value"
            :disabled="item.disabled"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label-width="200px" label="业务类型" prop="bizTyep">
        <el-select
          v-model="formData.bizTyep"
          placeholder="请选择业务类型"
          clearable
          :style="{ width: '100%' }"
        >
          <el-option
            v-for="(item, index) in bizTyepOptions"
            :key="index"
            :label="item.label"
            :value="item.value"
            :disabled="item.disabled"
          ></el-option>
        </el-select>
      </el-form-item>

      <el-form-item
        label-width="200px"
        label="收付款类型"
        prop="receiptPayType"
      >
        <el-select
          v-model="formData.receiptPayType"
          placeholder="请选择结算方式类别"
          clearable
          :style="{ width: '100%' }"
        >
          <el-option
            v-for="(item, index) in settlementCategoryOptions"
            :key="index"
            :label="item.label"
            :value="item.value"
            :disabled="item.disabled"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label-width="200px" label="名称" prop="title">
        <el-input
          v-model="formData.title"
          placeholder="请输入名称"
          clearable
          :style="{ width: '100%' }"
        ></el-input>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import { add } from "@/api/base/data";
import { updataKingBaseReceiptPayPurposeList,editKingKingBaseReceiptPayPurposeList } from "@/api/bim/outher";
export default {
  components: {},
  props: ["id"],
  data() {
    return {
      flag: false,
      formData: {
        bizCode: undefined,
        dataStatus: undefined,
        bizTyep: undefined,
        settlementCategory: undefined,
        receiptPayType: undefined,
        title: undefined,
      },
      rules: {
        bizCode: [
          {
            required: true,
            message: "请输入编码",
            trigger: "blur",
          },
        ],
        dataStatus: [
          {
            required: true,
            message: "请选择数据状态",
            trigger: "change",
          },
        ],
        bizTyep: [
          {
            required: true,
            message: "请选择业务类型",
            trigger: "change",
          },
        ],
        settlementCategory: [
          {
            required: true,
            message: "请选择结算方式类别",
            trigger: "change",
          },
        ],
        receiptPayType: [
          {
            required: true,
            message: "请输入收付款类型",
            trigger: "blur",
          },
        ],
        title: [
          {
            required: true,
            message: "请输入名称",
            trigger: "blur",
          },
        ],
      },
      dataStatusOptions: [
        {
          label: "选项一",
          value: 1,
        },
        {
          label: "选项二",
          value: 2,
        },
      ],
      bizTyepOptions: [
        {
          label: "是",
          value: 1,
        },
        {
          label: "否",
          value: 2,
        },
      ],
      settlementCategoryOptions: [
        {
          label: "收款",
          value: 1,
        },
        {
          label: "付款",
          value: 2,
        },
      ],
    };
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {
    if (this.id != "") {
      updataKingBaseReceiptPayPurposeList(this.id).then((res) => {
        this.formData = res.data;
        this.flag = true;
      });
    }
  },
  methods: {
    submitForm(cb) {
      if (this.flag) {
        this.$refs["elForm"].validate((valid) => {
                if (!valid) return;
                // TODO 提交表单
                editKingKingBaseReceiptPayPurposeList(this.formData, "KingBaseReceiptPayPurpose").then((res) => {
                    if (res.code === 200) {
                        cb();
                        this.$message.success("修改成功");
                        this.flag=false
                    }
                });
            });
      } else {
        this.$refs["elForm"].validate((valid) => {
          if (!valid) return;
          // TODO 提交表单
          add(this.formData, "KingBaseReceiptPayPurpose").then((res) => {
            if (res.code === 200) {
              cb();
              this.$message.success("新增成功");
            }
          });
        });
      }
    },
    resetForm() {
      this.$refs["elForm"].resetFields();
    },
  },
};
</script>
<style></style>
